<?php $this->load->view('layout/header'); ?>
<div class="supplier-content-page">
    <div class="product-test-h5">
        <ul class="breadcrumb">
            <li><a href="javascript:;">营销管理</a></li>
            <li><a href="javascript:;">账号管理</a></li>
            <li  class="active"><a href="javascript:;">编辑</a></li>
        </ul>
        <div class="product-alls">
            <div class="product-fonter">编辑</div>
            <form class="form-horizontal public-validate-form" action="<?php echo site_url('user/editPost')?>" method="post" id="tourismtemplet_add">
                <div class="form-group">
                    <label class="col-sm-1 control-label"><em>* </em>用户类型</label>
                    <div class="col-xs-6">
                        <?php foreach ($user_type as $key => $value) : ?>
                            <label class="radio-inline">
                                <input type="radio" name="user_type" value="<?php echo $key; ?>" <?php if ($key == $res->user_type):?> checked="checked" <?php endif;?>> <?php echo $value; ?>
                            </label>
                        <?php endforeach;?>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-1 control-label">用户昵称</label>
                    <div class="col-xs-6">
                        <input type="text" class="form-control" name="alias_name" value="<?php echo $res->alias_name ?>">
                        <input type="hidden" name="uid" value="<?php echo $res->uid ?>">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-1 control-label"><em>* </em>手机号码</label>
                    <div class="col-xs-6">
                        <input type="text" class="form-control mobile required" name="mobile_phone" value="<?php echo $res->mobile_phone ?>">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-1 control-label">　姓　　名</label>
                    <div class="col-xs-6">
                        <input type="text" class="form-control" name="contacter" value="<?php echo $res->contacter ?>">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-1 control-label"><em>* </em>性　　别</label>
                    <div class="col-xs-5">
                        <label class="radio-inline">
                            <input type="radio" name="sex_id" value="0" checked="checked"> 保密
                        </label>
                        <label class="radio-inline">
                            <input type="radio" name="sex_id" value="1"> 男
                        </label>
                        <label class="radio-inline">
                            <input type="radio" name="sex_id" value="2"> 女
                        </label>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-1 control-label"><em>* </em>状　　态</label>
                    <div class="col-xs-5">
                        <label class="radio-inline">
                            <input type="radio" name="status" value="1" checked="checked"> 启用
                        </label>
                        <label class="radio-inline">
                            <input type="radio" name="status" value="0"> 禁用
                        </label>
                    </div>
                </div>
                <div class="form-btn">
                    <a href="javascript:;">
                        <button class="btn btn-info" type="submit">保存</button>
                    </a>
                    <a href="<?php echo site_url('user/grid');?>">返回上一步</a>
                </div>
            </form>
        </div>
    </div>
</div>
<?php $this->load->view('layout/footer'); ?>
<script type="text/javascript">
    $("[name='status'][value='<?php echo $res->status ?>']").attr("checked", true);
    $("[name='sex_id'][value='<?php echo $res->sex_id ?>']").attr("checked", true);
    $('.form-horizontal').submit(function(){
        return false;
    }).validate({
        rules: {
            mobile_phone: {
                required: true,
                mobile:true,
                remote: {
                    url:hostUrl()+'/user/validateMobilePhone',
                    type: 'post',
                    dataType: 'json',
                    data: {
                        mobile_phone:function(json) {
                            return $('input[name=mobile_phone]').val();
                        },
                        uid:function(json) {
                            return $('input[name=uid]').val();
                        }
                    }
                }
            }
        },
        messages: {
            mobile_phone: {
                required: '请输入您的手机号码',
                mobile: '手机号码格式错误',
                remote: '手机号码已注册'
            }
        },
        submitHandler: function(f) {
            var obj = $('button[type=submit]')
            $.ajax({
                type: 'post',
                async: true,
                dataType : 'json',
                url: hostUrl() + '/user/editPost',
                data: $('form.form-horizontal').serialize(),
                beforeSend: function() {
                    obj.text('正在保存...').attr('disabled', true);
                },
                success: function(data) {
                    if (data.status) {
                        window.location.href = data.msg;
                    } else {
                        layerMessages(data.status, data.msg);
                    }
                    obj.text('重新保存').removeAttr('disabled');
                }
            });
        }
    });
</script>